﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using Maticsoft.Common;

namespace WEB.Client
{
    public partial class ClientKnowledgeView : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                int id =Convert.ToInt32( Request.QueryString["id"]);
                string subFile = "";
                switch (id)
                {
                    case 0:
                        subFile = "rule";
                        break;
                    case 1:
                        subFile = "business";
                        break;
                    case 2:
                        subFile = "case";
                        break;
                    case 3:
                        subFile = "notice";
                        break;
                    case 4:
                        subFile = "port";
                        break;
                    default:
                        return;
                }
                string folderFullName = Server.MapPath(@"~\document\" + subFile);
                DirectoryInfo TheFolder = new DirectoryInfo(folderFullName);
                
                int i = 0; //i指定了列表的序号
                foreach (FileInfo NextFile in TheFolder.GetFiles())
                {
                    if (NextFile.Name.Substring(0, 4) != "(内部)")
                    {
                        string strExten = System.IO.Path.GetExtension(NextFile.Name).ToString();
                        if (strExten == ".html" || strExten == ".txt" || strExten == ".pdf") //支持的格式
                        {
                            int index = NextFile.Name.LastIndexOf(".");
                            string fileName = NextFile.Name.Substring(4, index - 4);
                            listKnow.Items.Add(fileName);
                            listKnow.Items[i].Value = Server.MapPath(@"~\document\" + subFile + @"\" + NextFile.Name);
                            i++;
                        }
                    }
                }
                if (i == 0) MessageBox.Show(this, "暂时没有相关文件，如果需要请先上传~");
            }
        }

        protected void listKnow_Click(object sender, BulletedListEventArgs e)
        {
            string docName = listKnow.Items[e.Index].Value;
            Response.Redirect("~/knowledge/knowledgeRead.aspx?docName1=" + docName);
        }
    }
}